package com.huawei.eservice.demo;


import android.os.Environment;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class ExampleUnitTest {
    private static ArrayList<ArrayList<String>> recordList;
    private static String[] title = {"编号", "姓名", "性别", "年龄", "班级", "数学", "英语", "语文"};
    private static List<Student> students;

    public static void main(String[] art) {
        //模拟数据集合
        students = new ArrayList<>();
        for (int i = 1; i <= 10; i++) {
            students.add(new Student("小红" + i, "女", "12", "1" + i, "一班", "85", "77", "98"));
            students.add(new Student("小明" + i, "男", "14", "2" + i, "二班", "65", "57", "100"));
        }

        File file = new File("app/Record");
        if (!file.exists()) {
            file.mkdir();
        }
        String fileName = "app/Record/成绩表.xls";
        ExcelUtils.initExcel( fileName, title);
        ExcelUtils.writeObjListToExcel(getRecordData(), fileName);
    }


    /**
     * 将数据集合 转化成ArrayList<ArrayList<String>>
     *
     * @return
     */
    private static ArrayList<ArrayList<String>> getRecordData() {
        recordList = new ArrayList<>();
        for (int i = 0; i < students.size(); i++) {
            Student student = students.get(i);
            ArrayList<String> beanList = new ArrayList<String>();
            beanList.add(student.id);
            beanList.add(student.name);
            beanList.add(student.sex);
            beanList.add(student.age);
            beanList.add(student.classNo);
            beanList.add(student.math);
            beanList.add(student.english);
            beanList.add(student.chinese);
            recordList.add(beanList);
        }
        return recordList;
    }

}